package cn.mw.cmdb.param;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum FunctionModuleEnum {
    enableMonitor("enableMonitor", "运维监控"),
    enableAutomate("enableAutomate", "自动化"),
    enableConfigManage("enableConfigManage", "配置管理"),
    enableLogManage("enableLogManage", "日志管理"),
    processManage("processManage", "流程纳管"),
    financeReport("financeReport", "金融元上报");

    private String code;
    private String name;

    FunctionModuleEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static FunctionModuleEnum getEventSourceEnum(String code) {
        for (FunctionModuleEnum tableIdEnum : FunctionModuleEnum.values()) {
            if (tableIdEnum.getCode().equals(code)) {
                return tableIdEnum;
            }
        }
        return null;
    }

    public static List<String> getAllCodeEnum() {
        List<String> getAllCode = new ArrayList<>();
        for (FunctionModuleEnum tableIdEnum : FunctionModuleEnum.values()) {
            getAllCode.add(tableIdEnum.getCode());
        }
        return getAllCode;
    }

    public static String getModuleName(String code) {
        for (FunctionModuleEnum tableIdEnum : FunctionModuleEnum.values()) {
            if (tableIdEnum.getCode().equals(code)) {
                return tableIdEnum.getName();
            }
        }
        return null;
    }

    public static JSONArray getFunctionModule() {
        JSONArray jsonArray = new JSONArray();
        for (FunctionModuleEnum value : FunctionModuleEnum.values()) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("code", value.getCode());
            jsonObject.put("name", value.getName());
            jsonArray.add(jsonObject);
        }
        return jsonArray;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

}
